class dryCommon extends HTMLElement {
    constructor() {
        super();
        var e = this, t = C("url"), n = C("iframeUrl"), i = C("ref"), a = C("role"), l = C("scene", "none"),
            u = C("callback"), r = C("label"), o = C("help"), s = C("tip"), c = C("value"), d = C("name"),
            y = C("class"), p = C("placeholder"), m = C("variable"), h = C("submit"), f = C("reset"), $ = C("checked"),
            v = C("openText"), x = C("closeText"), b = C("block", 0), k = C("verify"), g = [], H = null, w = [], S = {};

        function C(t, n = "") {
            return e.hasAttribute(t) ? e.getAttribute(t) : n
        }

        function j(e) {
            return document.getElementById(e)
        }

        function T(e, t) {
            for (var n = e.split(","), i = 0; i < n.length; i++) if (n[i] == t) return !0;
            return !1
        }

        function M() {
            "selectOnly" == a ? S.selectHtml() : "dateOnly" == a ? S.dateHtml() : "timeOnly" == a ? S.timeHtml() : "datetimeOnly" == a ? S.datetimeHtml() : (g.push('<div class="layui-form-item">'), b ? "submit" != a && g.push(`<div class="layui-input-block" style="margin-left:0;">${r}</div>`) : g.push(`<label class="layui-form-label" id="${d}_label">${r}</label>`), "" != o || "color" == a ? g.push('<div class="layui-input-inline">') : b ? g.push('<div class="layui-input-block" style="margin-left:0;">') : g.push('<div class="layui-input-block">'), S[a + "Html"](), g.push("</div>"), "color" == a && g.push(`<div id="${d}-picker"></div>`), "" != o && g.push(`<div class="layui-form-mid layui-word-aux">${o}</div>`), g.push("</div>")), D()
        }

        function B(e) {
            return "top" == l ? e.unshift({key: "0", text: "作为顶级", class: ""}) : "all" == l ? e.unshift({
                key: "all",
                text: "全部",
                class: ""
            }) : "select" == l && e.unshift({key: "-1", text: "请选择", class: ""}), e
        }

        function O(e) {
            var t = e.jquery, n = e.form, i = e.laydate, l = e.layer;
            if (t("input.date").each((function () {
                i.render({elem: "#" + t(this).attr("id"), type: "date", format: "yyyy-MM-dd"})
            })), t("input.time").each((function () {
                i.render({elem: "#" + t(this).attr("id"), type: "time", format: "HH:mm:ss"})
            })), t("input.datetime").each((function () {
                i.render({elem: "#" + t(this).attr("id"), type: "datetime", format: "yyyy-MM-dd HH:mm:ss"})
            })), "" != s) {
                var u = "#" + d + "_label", r = null;
                t(u).mouseover((function () {
                    r = l.tips(s, u, {tips: 2, time: 1e4})
                })), t(u).mouseout((function () {
                    l.close(r)
                }))
            }
            T("select,selectOnly", a) && "" != d && n.on(`select(${d})`, (function (e) {
                window.dryCommonSelectChange && dryCommonSelectChange(e)
            })), n.render()
        }

        function _(e) {
            var t = e.transfer, n = d + "_transfer";
            t.render({
                elem: "#" + n, title: ["待选择", "已选择"], parseData: function (e) {
                    return {value: e.key, title: e.text}
                }, data: w, value: c.split(","), showSearch: !0, id: n, onchange: function (e, i) {
                    for (var a = [], l = t.getData(n), u = 0; u < l.length; u++) a.push(l[u].value);
                    j(d).value = a.join(",")
                }
            })
        }

        function q(e) {
            var t = e.colorpicker, n = e.jquery;
            t.render({
                elem: "#" + d + "-picker", color: c, predefine: !0, done: function (e) {
                    n("#" + d).val(e)
                }
            })
        }

        function I(e) {
            var t = e.jquery, n = e.layeditV2, i = n.build(d);
            setInterval((function () {
                var e = t("#" + d);
                e.hasClass("layui-hide") ? n.sync(i) : n.setContent(i, e.val(), !1)
            }), 1e3), t(".layedit-tool-html").click((function () {
                t(this).parent().parent().find("div.layui-layedit-iframe").toggleClass("layui-hide"), t(this).parent().parent().parent().find("textarea").toggleClass("layui-hide")
            }))
        }

        function L(e) {
            var t = e.jquery, n = e.icon;
            t("body").append("\n            <style>\n            .dry-box {\n                border: 1px solid #e6e6e6;\n                padding-left: 10px;\n            }\n            .dry-input-line-height {\n                line-height: 38px;\n            }\n            .dry-icon-box {\n                text-align: center;\n                border: 1px solid #e6e6e6;\n                margin-right: -1px;\n                margin-bottom: -1px;\n            }\n            .dry-icon-item {\n                line-height: 50px;\n            }\n            </style>\n            "), n.set(d + "_box")
        }

        function A(e) {
            var i = e, a = e.jquery, l = e.file;
            if (a("#" + d).parent().find(".selectButton").click((function () {
                l.doSelectButton(d, n)
            })), "" == c) return !1;
            !function (e, t, n, i) {
                fetch(e, {method: "post", body: t}).then((function (e) {
                    1 == e.ok && 200 == e.status && e.json().then((function (e) {
                        n(e)
                    }))
                })).catch((function (e) {
                    i(e)
                }))
            }(t, function (e) {
                var t = new FormData;
                for (var n in e) t.append(n, e[n]);
                return t
            }({dataIn: c}), (function (e) {
                !function (e) {
                    var t = "imageShowBox-" + d;
                    i.laytpl(l.fileSelectItem).render(e.data, (function (e) {
                        a("#" + t).html(e), l.setImageShow(t, !1)
                    }))
                }(e), function (e) {
                    var t = e.data.list;
                    i.each(t, (function (e, n) {
                        n.addSort = e, t[e] = n
                    })), a("#" + d).parent().find("textarea").html(JSON.stringify(t))
                }(e)
            }), null)
        }

        function D() {
            "" == i && (i = function () {
                var e = new Date, t = Math.random() + "";
                return "g_" + e.getTime() + "_" + t.substr(2)
            }(), e.insertAdjacentHTML("afterend", `<div id="${i}"></div>`)), j(i).innerHTML = g.join(""), "transfer" == a ? E(_) : "color" == a ? E(q) : "editor" == a ? E(I) : "icon" == a ? E(L) : "fileSelect" == a && E(A), E(O)
        }

        function E(t) {
            var n = window[u];
            n ? (n(t), e.setAttribute("ok", "1"), T("selectOnly", a) && window.dryCommonReady && dryCommonReady(e)) : setTimeout((function () {
                E(t)
            }), 500)
        }

        if (S.inputHtml = function () {
            var e = d;
            "" != k && (e = k), g.push(`<input type="text" lay-verify="${e}" class="layui-input ${y}" name="${d}" id="${d}" value="${c}" placeholder="${p}">`)
        }, S.dateHtml = function () {
            g.push(`<input type="text" lay-verify="${d}" class="layui-input date ${y}" name="${d}" id="${d}" value="${c}" placeholder="${p}">`)
        }, S.timeHtml = function () {
            g.push(`<input type="text" lay-verify="${d}" class="layui-input time ${y}" name="${d}" id="${d}" value="${c}" placeholder="${p}">`)
        }, S.datetimeHtml = function () {
            g.push(`<input type="text" lay-verify="${d}" class="layui-input datetime ${y}" name="${d}" id="${d}" value="${c}" placeholder="${p}">`)
        }, S.passwordHtml = function () {
            g.push(`<input type="password" lay-verify="${d}" class="layui-input ${y}" name="${d}" id="${d}" value="${c}" placeholder="${p}">`)
        }, S.textareaHtml = function () {
            g.push(`<textarea lay-verify="${d}" class="layui-textarea ${y}" name="${d}" id="${d}" placeholder="${p}">${c}</textarea>`)
        }, S.editorHtml = function () {
            g.push(`<textarea lay-verify="${d}" class="layui-textarea ${y}" name="${d}" id="${d}" placeholder="${p}" style="height:280px;">${c}</textarea>`)
        }, S.selectHtml = function () {
            for (var e in g.push(`<select name="${d}" id="${d}" lay-search="" lay-filter="${d}">`), w) {
                var t = w[e];
                T(c, t.key) ? g.push(`<option value="${t.key}" selected="">${t.text}</option>`) : g.push(`<option value="${t.key}">${t.text}</option>`)
            }
            g.push("</select>")
        }, S.buttonThemeHtml = function () {
            for (var e in w = [{key: "layui-btn-green", text: "墨绿"}, {
                key: "layui-btn-primary",
                text: "银灰"
            }, {key: "layui-btn-normal", text: "蓝色"}, {key: "layui-btn-warm", text: "橙色"}, {
                key: "layui-btn-danger",
                text: "赤色"
            }], g.push(`<select name="${d}" id="${d}">`), w) {
                var t = w[e];
                T(c, t.key) ? g.push(`<option value="${t.key}" selected="">${t.text}</option>`) : g.push(`<option value="${t.key}">${t.text}</option>`)
            }
            g.push("</select>")
        }, S.radioHtml = function () {
            for (var e in w) {
                var t = w[e];
                t.key == c ? g.push(`<input type="radio" name="${d}" value="${t.key}" title="${t.text}" lay-filter="${d}" checked>`) : g.push(`<input type="radio" name="${d}" value="${t.key}" title="${t.text}" lay-filter="${d}">`)
            }
        }, S.checkboxHtml = function () {
            for (var e in w) {
                var t = w[e];
                T(c, t.key) ? g.push(`<input type="checkbox" name="${d}[]" value="${t.key}" lay-skin="primary" title="${t.text}" checked>`) : g.push(`<input type="checkbox" name="${d}[]" value="${t.key}" lay-skin="primary" title="${t.text}">`)
            }
        }, S.checkboxBigHtml = function () {
            for (var e in w) {
                var t = w[e];
                T(c, t.key) ? g.push(`<input type="checkbox" name="${d}[]" value="${t.key}" title="${t.text}" checked>`) : g.push(`<input type="checkbox" name="${d}[]" value="${t.key}" title="${t.text}">`)
            }
        }, S.transferHtml = function () {
            g.push(`<input type="hidden" name="${d}" id="${d}" value="${c}">`), g.push(`<div id="${d}_transfer"></div>`)
        }, S.switchHtml = function () {
            var e = "";
            "" == $ || "true" == $ ? e = 'checked=""' : "auto" != $ || "1" != c && "yes" != c && "true" != c || (e = 'checked=""'), g.push(`<input type="checkbox" name="${d}" lay-skin="switch" lay-text="${v}|${x}" ${e}>`)
        }, S.colorHtml = function () {
            g.push(`<input type="text" lay-verify="${d}" class="layui-input ${y}" name="${d}" id="${d}" value="${c}" placeholder="${p}">`)
        }, S.submitHtml = function () {
            b ? g.push(`<button type="submit" class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="default">${h}</button>`) : g.push(`<button type="submit" class="layui-btn" lay-submit="" lay-filter="default">${h}</button>`), "" != f && g.push(`<button type="reset" class="layui-btn layui-btn-primary">${f}</button>`)
        }, S.iconHtml = function () {
            g.push(`<input type="hidden" name="${d}" id="${d}" value="${c}">`), g.push(`<div class="dry-box" id="${d}_box" data-id="${d}" style="cursor:pointer;"></div>`)
        }, S.fileSelectHtml = function () {
            var e = `\n            <div class="layui-card dry-skin-green">\n                <div class="layui-card-header layui-unselect dry-fold pointer">面板</div>\n                <div class="layui-card-body">\n                    <input type="hidden" name="${d}" id="${d}" value="${c}">\n                    <textarea class="layui-hide"></textarea>\n                    <button type="button" class="layui-btn selectButton">选择</button>\n                    <div class="box" id="imageShowBox-${d}" count="50" margin="10" width="150" height="150" style="margin-left:-10px;"></div>\n                </div>\n            </div>\n            `;
            g.push(e)
        }, "" == c) {
            var N = e.getElementsByTagName("textarea");
            N.length && (c = N[0].innerHTML)
        }
        if ("" == u && (u = "dryCallback"), T(["select", "radio", "checkbox", "checkboxBig", "transfer", "selectOnly"].join(","), a)) if ("" != m) {
            var J = window[m];
            J = B(J), w = (H = {data: {list: J}}).data.list, M()
        } else fetch(t).then((function (e) {
            1 == e.ok && 200 == e.status && e.json().then((function (e) {
                H = e, w = B(w = e.data.list), H.data.list = w, M()
            }))
        })).catch((function (e) {
            console.log(e)
        })); else "tag" == a ? function () {
            var t = e.parentNode.querySelector("textarea").innerHTML;
            for (var n in t = JSON.parse(t), w = t.data.list) {
                var i = w[n];
                T(c, i.key) && (i.class || (i.class = "layui-bg-gray"), g.push(`<span class="layui-badge ${i.class}">${i.text}</span>`))
            }
            D()
        }() : M()
    }
}

window.customElements.define("dry-common", dryCommon);